<!DOCTYPE html>
<html>
<head>
   <!-- 页面meta -->
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <title>传智健康</title>
   <meta name="description" content="传智健康">
   <meta name="keywords" content="传智健康">
   <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
   <!-- 引入样式 -->
   <link rel="stylesheet" href="../plugins/elementui/index.css">
   <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="../css/style.css">

   <style>
      .el-row {
         margin-bottom: 20px;
      }
      .el-col {
         border-radius: 4px;
      }
   </style>
</head>
<body class="hold-transition">
<div id="app">
   <div class="content-header">
      <h1>健康干预
         <small>方案模板</small>
      </h1>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
         <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
         <el-breadcrumb-item>健康干预</el-breadcrumb-item>
         <el-breadcrumb-item>方案模板</el-breadcrumb-item>
      </el-breadcrumb>
   </div>
   <div class="app-container">
      <div class="box">
         <!--搜索框-->
         <div class="filter-container">
            <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                      class="filter-item"></el-input>
            <el-button @click="findPage()" class="dalfBut">查询</el-button>
            <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
         </div>
         <!--搜索框/-->

         <!--分页数据-->
         <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"></el-table-column>
            <el-table-column prop="title" label="标题" align="center"></el-table-column>
            <el-table-column prop="keyword" label="关键词" align="center"></el-table-column>
            <el-table-column prop="uers" label="适用人群" align="center"></el-table-column>
            <el-table-column prop="target" label="方案目标" align="center"></el-table-column>
            <el-table-column prop="isUse" label="启用" align="center"></el-table-column>
            <el-table-column prop="remark" label="备注" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
               <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                  <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">禁用</el-button>
                  <!--scope.row代表当前行的对象-->
                  <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
               </template>
            </el-table-column>
         </el-table>
         <!--分页数据/-->

         <!--分页条-->
         <div class="pagination-container">
            <el-pagination
               class="pagiantion"
               @current-change="handleCurrentChange"
               :current-page="pagination.currentPage"
               :page-size="pagination.pageSize"
               layout="total, prev, pager, next, jumper"
               :total="pagination.total">
            </el-pagination>
         </div>
         <!--分页条/-->

         <!-- 编辑标签弹层 -->
         <div class="add-form">
            <el-dialog v-if="dialogFormVisible" title="新增模板" :visible.sync="dialogFormVisible">
               <template>
                  <el-tabs v-model="activeName" @tab-click="handleClick">
                     <!--基本信息-->
                     <el-tab-pane label="基本信息" name="first">
                        <el-row>
                           <el-col :span="12">
                              <el-col :span="4">档案号:</el-col>
                              <el-col :span="20">1234234</el-col>
                           </el-col>
                           <el-col :span="12">
                              <el-col :span="4">姓名:</el-col>
                              <el-col :span="20">性别</el-col>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="12">
                              <el-col :span="4">年龄:</el-col>
                              <el-col :span="20">23</el-col>
                           </el-col>
                           <el-col :span="12">
                              <el-col :span="4">性别:</el-col>
                              <el-col :span="20">是的佛诞节佛开电脑</el-col>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">疾病史:</el-col>
                           <el-col :span="22">是的佛诞节佛开电脑</el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">遗传史:</el-col>
                           <el-col :span="22">是的佛诞节佛防守打法电风扇水电费爽肤水水电费水电费水电费分水电费开电脑</el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">手术史:</el-col>
                           <el-col :span="22">是的大幅度发斯蒂芬第三方发多少发送到是的大幅度发斯蒂芬第三方发多少发送到地方反反复复所多地方分分胜是的大幅度发斯蒂芬第三方发多少发送到地方反反复复所多地方分分胜地方反反复复所多地方分分胜负佛诞节佛开电脑</el-col>
                        </el-row>

                     </el-tab-pane>
                     <!--基本信息/-->
                     <!--饮食干预-->
                     <el-tab-pane label="饮食干预" name="second">
                        <template>
                           <el-table :data="tableData" style="width: 100%">
                              <el-table-column prop="date" label="档案号" width="180"></el-table-column>
                              <el-table-column prop="name" label="体检日期" width="180"></el-table-column>
                              <el-table-column prop="address" label="体检套餐"></el-table-column>
                              <el-table-column label="查看体检报告" width="120">
                                 <template slot-scope="scope">
                                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                                 </template>
                              </el-table-column>
                           </el-table>
                        </template>
                     </el-tab-pane>
                     <!--饮食干预/-->
                     <!--运动干预-->
                     <el-tab-pane label="运动干预" name="third">
                        <template>
                           <el-table :data="tableData" style="width: 100%">
                              <el-table-column prop="date" label="档案号" width="180"></el-table-column>
                              <el-table-column prop="name" label="风险评估日期" width="180"></el-table-column>
                              <el-table-column prop="address" label="问卷状态"></el-table-column>
                              <el-table-column label="查看评估报告" width="120">
                                 <template slot-scope="scope">
                                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                                 </template>
                              </el-table-column>
                           </el-table>
                        </template>
                     </el-tab-pane>
                     <!--运动干预/-->
                     <el-tab-pane label="确认分类:" name="fourth">
                        <el-row>
                           <el-col :span="4">确认分类</el-col>
                           <el-col :span="20">
                              <el-checkbox-group v-model="checkList">
                                 <el-checkbox label="复选框 A"></el-checkbox>
                                 <el-checkbox label="复选框 B"></el-checkbox>
                                 <el-checkbox label="复选框 1"></el-checkbox>
                                 <el-checkbox label="复选框 2"></el-checkbox>
                                 <el-checkbox label="复选框 3"></el-checkbox>
                                 <el-checkbox label="复选框 4"></el-checkbox>
                                 <el-checkbox label="复选框 5"></el-checkbox>
                                 <el-checkbox label="复选框 6"></el-checkbox>
                                 <el-checkbox label="复选框 7"></el-checkbox>
                                 <el-checkbox label="复选框 8"></el-checkbox>
                                 <el-checkbox label="复选框 9"></el-checkbox>
                                 <el-checkbox label="复选框 10"></el-checkbox>
                                 <el-checkbox label="复选框 11"></el-checkbox>
                              </el-checkbox-group>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="4">健康管理师:</el-col>
                           <el-col :span="20">
                              <el-select v-model="value" placeholder="请选择">
                                 <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                 </el-option>
                              </el-select>
                           </el-col>
                        </el-row>
                     </el-tab-pane>
                  </el-tabs>
               </template>
               <div slot="footer" class="dialog-footer">
                  <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                  <el-button type="primary" @click="handleEdit()">保存</el-button>
               </div>
            </el-dialog>
         </div>
      </div>
   </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
   var app = new Vue({
      el: '#app',
      data: {
         dataList:[],//列表数据
         options: [{
            value: '选项1',
            label: '黄金糕'
         }, {
            value: '选项2',
            label: '双皮奶'
         }, {
            value: '选项3',
            label: '蚵仔煎'
         }, {
            value: '选项4',
            label: '龙须面'
         }, {
            value: '选项5',
            label: '北京烤鸭'
         }],
         value: '',
         checkList: ['复选框 A'],//确认分类复选框数据
         tableData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
         }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
         }],
         activeName: 'first',
         form: {
            name: '',
            region: '',
            date1: '',
            date2: '',
            delivery: false,
            type: [],
            resource: '',
            desc: ''
         },
         showDialog: true, //弹框是否为新表单
         pagination: {//分页相关模型数据
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的记录数
            total: 0,//总记录数
            queryString: null//查询条件
         },
         dialogFormVisible: false,//编辑表单是否可见
      },

      //钩子函数，VUE对象初始化完成后自动执行,
      created() {
         //初始化分页查询
         this.findPage();

      },

      methods: {
         handleClick(tab, event) {
            console.log(tab, event);
         },
         onSubmit() {

         },
         //编辑
         handleEdit() {
            //1.执行表单校验
            this.$refs['dataEditForm'].validate((valid) => {
               if (valid) {//校验成功
                  //2.发送ajax请求
                  axios.post("/checkItem/update.do", this.formData).then((res) => {
                     //2.1隐藏表单
                     this.dialogFormVisible4Edit = false;

                     if (res.data.flag) { //修改成功
                        //2.3成功提示框
                        this.$message({
                           message: res.data.message,
                           type: 'success'
                        });

                     } else { //修改失败
                        //失败提示框
                        this.$message.error(res.data.message);
                     }

                  }).catch((err) => {
                     this.showMessage(err);
                  }).finally(() => {
                     //此处不能重置当前页：用户体验，修改后可以立马定位改的位置
                     //2.2分页查询
                     this.findPage(1); //不重置当前页
                  });
               } else {//表单校验失败

                  this.$message.error("表单数据校验失败");
                  return false;
               }
            });
         },

         //添加
         handleAdd() {
            //理解$refs:参数:指定form的ref属性值
            this.$refs['dataAddForm'].validate((valid) => {
               //alert(valid);//测试
               if (valid) {//校验成功
                  //隐藏添加表单,this可以指代vue对象
                  this.dialogFormVisible = false;//隐藏

                  //发送ajax请求
                  axios.post('/checkItem/add.do', this.formData).then(res => {
                     //处理结果{flag:true,message:'hello',data:{..}}
                     //console.log(res.data);//测试
                     if (res.data.flag) {//添加成功

                        //成功弹框
                        this.$message({
                           message: res.data.message,
                           type: 'success'
                        });
                        //调用分页查询
                        this.findPage();
                     } else {//添加失败
                        //失败弹框:使用后台的数据填充
                        this.$message.error(res.data.message)
                     }
                  }).catch(err => { //报错执行
                     this.showMessage(err);
                  });

               } else {//校验失败
                  //弹框
                  this.$message.error('表单数据校验失败');
                  return false;
               }
            });
         },

         //分页查询
         findPage(isCustom) { //参数:表示是否定制当前页
            //debugger;
            //0.判断是从查询按钮调用此方法
            if (!isCustom) {//无惨:默认重置当前页
               //将当前页码重置为1
               this.pagination.currentPage = 1;
            }

            //console.log("hello findPage!");//测试
            //1.封装参数,当前页,每页尺寸,查询条件
            var para = {
               currentPage: this.pagination.currentPage,
               pageSize: this.pagination.pageSize,
               queryString: this.pagination.queryString
            };


            //2.发送ajax请求
            axios.post("/checkItem/findPage.do", para).then(res => {
               //获取返回结果{total:100,rows:[行数据]},赋值给分页模型
               this.pagination.total = res.data.total;
               //this.dataList = res.data.rows;//赋值表数据
            }).catch(err => {
               console.log(err);
            }).finally();
         },

         // 重置表单
         resetForm() {
            this.formData = {};
         },

         // 弹出添加窗口
         handleCreate() {
            //console.log("create");//测试
            this.resetForm();
            this.dialogFormVisible = true;
         },

         // 弹出编辑窗口
         handleUpdate(row) {//不使用row直接回显,可能其他管理员已经删除了此条数据,故以数据库为准
            //1.设置显示编辑窗口
            this.resetForm();
            this.dialogFormVisible4Edit = true;

            //2.发送ajax,回显数据
            axios.get("/checkItem/findById/" + row.id + ".do").then((res) => {
               if (res.data.flag) {//查询成功
                  //设置回显数据
                  this.formData = res.data.data;

               } else {//回显失败原因:多线程同时操作,页面数据已经不存在,故无法回显
                  this.$message.error("获取数据失败,请刷新当前页面")
               }
            }).catch().finally();
         },

         //切换页码
         handleCurrentChange(currentPage) {//当前页更改时回调函数
            //currentPage为新的当前页
            //1.修改当前页数据
            this.pagination.currentPage = currentPage;
            //2.调用分页查询方法
            this.findPage(1); //使用自定义当前页
         },

         // 删除
         handleDelete(row) {//row为当前行json对象

            //确认框
            this.$confirm('确认删除吗?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning'
            }).then(() => {//点确认,回调
               //发送ajax请求
               axios.delete("/checkItem/delete/" + row.id + ".do").then((res) => {
                  console.log(res.data);//测试
                  //判断是否删除成功
                  if (res.data.flag) {//删除成功
                     //成功框
                     app.$message({
                        message: res.data.message,
                        type: 'success'
                     });

                  } else {//删除失败
                     //失败框
                     this.$message.error(res.data.message);
                  }
               }).catch((err) => {//报错,打印日志
                  console.log(err);
                  //调用方法显示错误信息
                  this.showMessage(err);
               }).finally(() => {//始终执行

                  this.findPage(1);//调用分页查询

               });

            }).catch(() => {//点取消,回调
               //取消框
               this.$message({
                  type: 'info',
                  message: '已取消操作'
               });
            });
         },

         //显示报错时的信息
         showMessage(err) {
            if (err == "Error: Request failed with status code 403") {
               this.$message.error("无访问权限");
            } else {
               this.$message.error("未知错误");
            }
         }

      }
   });
</script>

</html>